import java.util.*;

public class HomeWork {
    public static void main(String[] args) {
        //第一题
        Map<Integer, String> map = new HashMap<Integer, String>();
        map.put(1, "Amy");
        map.put(2, "Joe");
        map.put(3, "Tom");
        map.put(4, "Susan");
        Set set = map.keySet();
        for (Object obj : set) {
            System.out.println(obj + "" + map.get(obj));
        }
        Scanner scan = new Scanner(System.in);
        System.out.println("输入要添加的名字");
        String userIPt = scan.next();
        map.put(5, userIPt);
        map.remove(4);
        map.remove(3);
        map.put(3, "Tommy");
        System.out.println("");
        Set setNew = map.keySet();
        for (Object obj : set) {
            System.out.println(obj + "" + map.get(obj));
        }
        //第二题
//        String[] str = {"a", "b", "a", "b", "c", "a", "b", "c", "b"};
//        Map<Character, Integer> map1 = new HashMap<Character, Integer>();
//        int a = 0;
//        int b = 0;
//        int c = 0;
//        for (int i = 0; i < str.length; i++) {
//            if (str[i].equals("a")) {
//                a++;
//            } else if (str[i].equals("b")) {
//                b++;
//            } else {
//                c++;
//            }
//        }
//        map1.put('a', a);
//        map1.put('b', b);
//        map1.put('c', c);
//        Set set1 = map1.keySet();
//        for (Object obj : set1) {
//            System.out.println(obj + "出现了：" + map1.get(obj) + "次");
//        }
        String[] strings = {"a", "b", "a", "b", "c", "a", "b", "c", "b"};
        Map map2 = new HashMap();
        List list = new ArrayList();

        for (int i = 0; i < strings.length; i++) {
            list.add(strings[i]);
        }
        System.out.println(list);

        HashSet set1 = new HashSet();
        set1.addAll(list);
        System.out.println(set1);

        ArrayList list1 = new ArrayList();
        list1.addAll(set1);//将set转为list
        System.out.println(list1);

        int changeTime = 0;
        for (int i = 0; i < list1.size(); i++) {
            for (int j = 0; j < strings.length; j++) {
                if (list1.get(i).equals(strings[j])) {
                    changeTime++;
                    map2.put(list1.get(i), changeTime);
                }
            }
            changeTime = 0;
        }
        System.out.println(map2);
    }
}
